package copyengine.ui.component.button
{

	import flash.display.MovieClip;

	import copyengine.ui.component.button.animation.ICESelectedButtonAnimation;

	public class CESelectableButton extends CEButton
	{
		/**
		 * attribute to record current state is selected or not.
		 */
		private var isSelected:Boolean=false;

		/**
		 * define
		 * Is when user click the btn then auto set the btn to selected.
		 */
		private var isClickToSelected:Boolean;

		public function CESelectableButton(_buttonBg:MovieClip,
										   _labelTextKey:String=null,
										   _isClickToSelected:Boolean=true,
										   _onClickCallBackFunction:Function=null)
		{
			super(_buttonBg, _labelTextKey, _onClickCallBackFunction);
			isClickToSelected=_isClickToSelected;
			isSelected=false;
		}

		//========================
		//==GET SET 屬性
		//========================

		/**
		 * 取得当前按钮选择状态
		 */
		public function get selected():Boolean
		{
			return isSelected;
		}

		/**
		 * 设置当前按钮选择状态
		 */
		public function set selected(_val:Boolean):void
		{
			if (isSelected != _val)
			{
				isSelected=_val;
				selectedButtonAnimation && selectedButtonAnimation.onSelectedChange(isSelected);

				boundFont();
			}
		}

		/**
		 * 如果改值为True则表示每次点击会自动更改按钮的选择状态
		 */
		public function get clickToSelect():Boolean
		{
			return isClickToSelected;
		}

		/**
		 * 如果改值为True则表示每次点击会自动更改按钮的选择状态
		 */
		public function set clickToSelect(_val:Boolean):void
		{
			isClickToSelected=_val;
		}


		//=====================
		//==Override function
		//=====================

		/**
		 * 在MouseDown时候需要
		 */
		override final protected function doOnClickButton():void
		{
			isClickToSelected ? selected=!selected : null;
		}

		//=====================
		//==Private Function
		//=====================

		/**
		 * 取得SelectedButton的Animation
		 * 在这里需要对父类的ButtonAnimation进行一次强转
		 */
		private function get selectedButtonAnimation():ICESelectedButtonAnimation
		{
			return animation as ICESelectedButtonAnimation;
		}

	}
}
